package com.softtown.modules.dapai.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.softtown.common.service.impl.BaseServiceImpl;
import com.softtown.common.utils.ConvertUtils;
import com.softtown.modules.dapai.dao.CompMacTypeDao;
import com.softtown.modules.dapai.dto.CompMacTypeDTO;
import com.softtown.modules.dapai.entity.CompMacTypeEntity;
import com.softtown.modules.dapai.service.CompMacTypeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
* @Author: Ding Ya Yong
* @Description: 设备分类
* @date: 2022/1/2 11:38
* @Param:
* @return:
*/

@Service
public class CompMacTypeServiceImpl extends
        BaseServiceImpl<CompMacTypeDao, CompMacTypeEntity> implements CompMacTypeService {



    @Override
    public PageInfo<CompMacTypeDTO> getMacTypePageList(CompMacTypeDTO compMacTypeDTO) {
        Integer pageSize = compMacTypeDTO.getPageSize();
        Integer page = compMacTypeDTO.getPage();
        if (pageSize > 0 && page > 0) {
            PageHelper.startPage(page, pageSize);
        }
        List<CompMacTypeDTO> compMacTypeDTOList =
                baseDao.getMacTypePageList(compMacTypeDTO.getCompId(), compMacTypeDTO.getParam());
        return  new PageInfo<>(compMacTypeDTOList);
    }

    @Override
    public CompMacTypeEntity getMacTypeById(Long compId, Long id) {
        return baseDao.getMacTypeById(compId, id);
    }

    @Override
    @Transactional
    public void addMacType(CompMacTypeDTO compMacTypeDTO) {
        CompMacTypeEntity compMacTypeEntity =ConvertUtils
                .sourceToTarget(compMacTypeDTO, CompMacTypeEntity.class);
        insert(compMacTypeEntity);
    }

    @Override
    @Transactional
    public void updateMacType(CompMacTypeDTO compMacTypeDTO) {
        CompMacTypeEntity compMacTypeEntity =ConvertUtils
                .sourceToTarget(compMacTypeDTO, CompMacTypeEntity.class);
        updateById(compMacTypeEntity);
    }

    @Override
    public void deleteMacType(CompMacTypeDTO compMacTypeDTO) {
        baseDao.deleteMacType(compMacTypeDTO.getCompId(), compMacTypeDTO.getId());
    }

    @Override
    public List<CompMacTypeDTO> listForMacType(CompMacTypeDTO compMacTypeDTO) {
        List<CompMacTypeDTO> compMacTypeDTOList =
                baseDao.listForMacType(compMacTypeDTO.getCompId(), compMacTypeDTO.getParam());
        return  compMacTypeDTOList;
    }







}
